package test4_16.demo01;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TCPClientTest {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        try {
            Socket socket = new Socket("localhost",8888);
            System.out.println("客户端与服务器连接成功");

            PrintWriter pw = new PrintWriter(socket.getOutputStream());
            System.out.println("开始聊天");

            while (true){
                String message = scanner.nextLine();
                pw.println(message);
                pw.flush();
                if (message.equals("拜拜")){
                    break;
                }
            }

            System.out.println("聊天结束");
            pw.close();
            socket.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
